package com.my.goodsmanage.entity;

import com.my.goodsmanage.enums.ResponseEnum;
import lombok.Data;

/**
 * @author 徐佳辉
 * @date 2020/8/4 19:56
 */
@Data
public class R<T> {

    private boolean success;
    private String msg;
    private T data;

    public R() {
    }

    public R(String msg) {
        this.msg = msg;
    }

    public R(boolean success, String msg, T data) {
        this.success = success;
        this.msg = msg;
        this.data = data;
    }

    public R(boolean success, String msg) {
        this.success = success;
        this.msg = msg;
    }

    public R(boolean success, T data) {
        this.success = success;
        this.data = data;
    }

    public static <T> R<T> success(){
        return new R<T>(ResponseEnum.SUCCESS.isSuccess(),ResponseEnum.SUCCESS.getMsg());
    }
    public static <T> R<T> success(T data){
        return new R<T>(ResponseEnum.SUCCESS.isSuccess(),data);
    }
    public static <T> R<T> success(String msg){
        return new R<T>(ResponseEnum.SUCCESS.isSuccess(),msg);
    }
    public static <T> R<T> success(T data,String msg){
        return new R<T>(ResponseEnum.SUCCESS.isSuccess(),msg,data);
    }

    public static <T> R<T> error(){
        return new R<T>(ResponseEnum.ERROR.isSuccess(),ResponseEnum.ERROR.getMsg());
    }
    public static <T> R<T> error(String msg){
        return new R<T>(ResponseEnum.ERROR.isSuccess(),msg);
    }
    public static <T> R<T> error(T data){
        return new R<T>(ResponseEnum.ERROR.isSuccess(),data);
    }
    public static <T> R<T> error(T data,String msg){
        return new R<T>(ResponseEnum.ERROR.isSuccess(),msg,data);
    }

}
